<?php require("admin-header.php");

if (!(isset($_SESSION['administrator']))){
	echo "<a href='../loginpage.php'>Please Login First!</a>";
	exit(1);
}?>
<?php if(isset($_POST['do'])){
	require_once("../include/check_post_key.php");
	if (isset($_POST['rjpid'])){
		$rjpid=intval($_POST['rjpid']);
		$sql="UPDATE `solution` SET `result`=1 WHERE `problem_id`=".$rjpid;
		mysql_query($sql) or die(mysql_error());
		$sql="delete from `sim` WHERE `s_id` in (select solution_id from solution where `problem_id`=".$rjpid.")";
		mysql_query($sql) or die(mysql_error());
		$url="../status.php?problem_id=".$rjpid;
		echo "Rejudged Problem ".$rjpid;
		echo "<script>location.href='$url';</script>";
	}
	else if (isset($_POST['rjsid'])){
		$rjsid=intval($_POST['rjsid']);
		$sql="UPDATE `solution` SET `result`=1 WHERE `solution_id`=".$rjsid;
		mysql_query($sql) or die(mysql_error());
		$sql="delete from `sim` WHERE `s_id`=".$rjsid;
		mysql_query($sql) or die(mysql_error());
		$url="../status.php?top=".($rjsid+1);
		echo "Rejudged Runid ".$rjsid;
		echo "<script>location.href='$url';</script>";
	}
}
?>
<center><h2>重 测</h2></center>
<form class="form-horizontal col-sm-6 col-sm-offset-2" action="rejudge.php" method="post">
    <div class="form-group">
        <label class="col-sm-5 control-label">题目编号</label>
        <div class="col-sm-7">
        <input class="form-control" name="rjpid" type="text"/></div>
    </div>
	<input type='hidden' name='do' value='do'>
    <div class="form-group">
        <div class="col-sm-offset-5 col-sm-7">
            <input type="submit" class="btn btn-primary col-sm-8" value="提交"/>
        </div>
    </div>
		<?php require_once("../include/set_post_key.php");?>
</form>
	
<form class="form-horizontal col-sm-6 col-sm-offset-2" action="rejudge.php" method="post">
    <div class="form-group">
        <label class="col-sm-5 control-label">运行编号</label>
        <div class="col-sm-7">
        <input class="form-control" name="rjsid" type="text"/></div>
    </div>
	<input type='hidden' name='do' value='do'>
	<input type=hidden name="postkey" value="<?php echo $_SESSION['postkey']?>">
	<div class="form-group">
        <div class="col-sm-offset-5 col-sm-7">
            <input type="submit" class="btn btn-primary col-sm-8" value="提交"/>
        </div>
    </div>
</form>
